package mogowtools.client.fx;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.UIObject;

public class Slider {

	private JavaScriptObject slider;
	private Element elem;
	private Options options;
	private boolean shown = true;
	
	public Slider(UIObject element)
	{
		this.elem = element.getElement();
		this.options = new Options();
		this.slider = newSliderObject();
	}
	
	public Slider(UIObject element, Options opts)
	{
		this.elem = element.getElement();
		this.options = opts;
		this.slider = newSliderObject();
	}

	public JavaScriptObject getOptions()
	{
		return this.options.value();
	}

	public void slideIn()
	{
		doSlideIn();
		this.shown = true;
	}
	
	public void slideOut()
	{
		doSlideOut();
		this.shown = false;
	}
	
	public void show()
	{
		doShow();
		this.shown = true;
	}
	
	public void hide()
	{
		doHide();
		this.shown = false;
	}
	
	public void toggle()
	{
		doToggle();
		this.shown = !this.shown;
	}
	
	public boolean isShown()
	{
		return this.shown;
	}
	
	public native void doSlideIn()
	/*-{
		var fx = this.@mogowtools.client.fx.Slider::slider;
		fx.slideIn();
	}-*/;
	
	public native void doSlideOut()
	/*-{
		var fx = this.@mogowtools.client.fx.Slider::slider;
		fx.slideOut();
	}-*/;
	
	public native void doShow()
	/*-{
		var fx = this.@mogowtools.client.fx.Slider::slider;
		fx.show();
	}-*/;
	
	public native void doHide()
	/*-{
		var fx = this.@mogowtools.client.fx.Slider::slider;
		fx.hide();
	}-*/;
	
	public native void doToggle()
	/*-{
		var fx = this.@mogowtools.client.fx.Slider::slider;
		fx.toggle();
	}-*/;

	private native JavaScriptObject newSliderObject()
	/*-{
		return new $wnd.Fx.Slide(
			this.@mogowtools.client.fx.Style::elem, 
			this.@mogowtools.client.fx.Style::getOptions()());
	}-*/;
	
}
